package a.b.mvc6.service;

import a.b.mvc6.mapper.StudentsMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;


@Service
@Slf4j
public class MySchedule {

    @Autowired
    private StudentsMapper studentsMapper;

    @Autowired
    private MyAsync myAsync;

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    // 使用cron 表达式，下面表示定时任务每10秒执行一次
    // @Scheduled(cron = "*/10 * * * * ?")
    public void cron() {

        studentsMapper.selectByPrimaryKey(1L);
        log.info(" cron result time:{}", LocalDateTime.now());
        log.info("开始异步任务！");
        stringRedisTemplate.opsForValue().set("giao", "之");
        myAsync.asyncMethod();
    }

}
